package com.egao.appo.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.appo.entity.Introduction;
import com.egao.appo.service.IntroductionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 介绍记录
 * @author : Doman
 * @date : 2021-07-23 16:57:31
 * @version ：1.0
 */

@Api(tags = "介绍记录")
@RestController
@RequestMapping("/api/appo/introduction")
public class IntroductionController extends BaseController {

	@Autowired
	private IntroductionService introductionService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('appo:introduction:list')")
    //@OperLog(value = "介绍记录", desc = "分页查询")
    @ApiOperation(value ="分页查询介绍记录",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "appoId:用户id\n" +
        "content:约见内容\n" +
        "operateUserId:操作人\n" +
        "remark:备注\n" +
        "introDate:约见时间\n" +
        "orderNum:排序\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "GET")
    @ApiPageParam
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, Introduction introduction) throws Exception{
        return introductionService.list(page, introduction, getLoginUser());
    }

    /**
     * 查询全部介绍记录
     */
    @PreAuthorize("hasAuthority('appo:introduction:list')")
    //@OperLog(value = "介绍记录", desc = "查询全部")
    @ApiOperation("查询全部介绍记录")
    @GetMapping()
    public JsonResult list(Introduction introduction){
        return introductionService.list(introduction, getLoginUser());
    }

    /**
     * 根据id查询介绍记录
     */
    @PreAuthorize("hasAuthority('appo:introduction:list')")
    //@OperLog(value = "介绍记录", desc = "根据id查询")
    @ApiOperation("根据id查询介绍记录")
    @GetMapping("/get")
    public JsonResult get(Introduction introduction) {
        return introductionService.getById(introduction);
		// 使用关联查询
        //PageParam<introduction> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<introduction> records = introductionService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加介绍记录
     */
    @PreAuthorize("hasAuthority('appo:introduction:save')")
    @OperLog(value = "介绍记录", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加介绍记录",notes = "" +
            "appoId:用户id\n" +
            "content:约见内容\n" +
            "operateUserId:操作人\n" +
            "remark:备注\n" +
            "introDate:约见时间\n" +
            "orderNum:排序\n" +
        "",httpMethod = "POST")
    @PostMapping()
    public JsonResult save(Introduction introduction) {
        return introductionService.save(introduction, getLoginUser());
    }

    /**
     * 修改介绍记录
     */
    @PreAuthorize("hasAuthority('appo:introduction:update')")
    @OperLog(value = "介绍记录", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改介绍记录",notes = "" +
            "id:id\n" +
            "appoId:用户id\n" +
            "content:约见内容\n" +
            "operateUserId:操作人\n" +
            "remark:备注\n" +
            "introDate:约见时间\n" +
            "orderNum:排序\n" +
        "",httpMethod = "PUT")
    @PutMapping()
    public JsonResult update(Introduction introduction) {
        return introductionService.update(introduction, getLoginUser());
    }

    /**
     * 删除介绍记录
     */
    @PreAuthorize("hasAuthority('appo:introduction:remove')")
    @OperLog(value = "介绍记录", desc = "删除", result = true)
    @ApiOperation("删除介绍记录")
    @DeleteMapping("/remove")
    public JsonResult remove(Introduction introduction ) {
        return introductionService.remove(introduction, getLoginUser());
    }

    /**
     * 批量添加介绍记录
     */
    /**@RequiresPermissions("appo:introduction:save")
    @OperLog(value = "介绍记录", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Introduction> list) {
        if (introductionService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改介绍记录
     */
    /**@RequiresPermissions("appo:introduction:update")
    @OperLog(value = "介绍记录", desc = "批量修改", result = true)
    @ResponseBody
    @PutMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Introduction> batchParam) {
        if (batchParam.update(introductionService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除介绍记录
     */
    /**@RequiresPermissions("appo:introduction:remove")
    @OperLog(value = "介绍记录", desc = "批量删除", result = true)
    @ResponseBody
    @DeleteMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (introductionService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
